import numpy
import pandas as pd
import datetime
import seaborn as sns
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objs as go
%matplotlib inline
df = pd.read_csv('covid_19_india.csv')
dt = df['Date'] # Restore Date in another variable to preserve its d_type
df['Date'] = pd.to_datetime(df['Date'], format='%d-%m-%Y')
df = df.sort_values(by='Date',ascending=True)
df.columns
df = df.drop(['Sno', 'Time', 'ConfirmedForeignNational', 'ConfirmedIndianNational'], axis = 1)
df.columns
fig = plt.figure(figsize =(12, 4.8))
plt.plot(df.Date,df.Confirmed)
plt.title("COVID-19 INDIA")
plt.xticks(rotation=60)
plt.xlabel("Date",labelpad=10)
plt.ylabel("Number of Cases",labelpad=10)
plt.show()
fig = plt.figure(figsize =(12, 4.8))
plt.plot(df.Date,df.Deaths,color='red')
plt.title("COVID-19 INDIA")
plt.xticks(rotation=60)
plt.xlabel("Date",labelpad=10)
plt.ylabel("Number of Deaths",labelpad=10)
plt.show()
sw_date = df.melt(id_vars='Date', value_vars=['Confirmed', 'Cured', 'Deaths'], var_name='Ratio', value_name='Value')
fig = px.line(sw_date, x="Date", y="Value", color='Ratio',)
fig.show()
fig = plt.figure(figsize =(12, 4.8))
ax = fig.add_axes([0,0,1,1])
ax.bar(df['State/UnionTerritory'],df['Confirmed'], color = list('rgbkymc'), width = 0.7,align='center')
plt.title('COVID-19 INDIA')
plt.xticks(rotation=90)
plt.xlabel('State Name')
plt.ylabel('Number of Cases')
plt.show()
fig = plt.figure(figsize =(12, 4.8))
pvt = pd.pivot_table(df,index='State/UnionTerritory', values='Confirmed', columns='Date')
sns.heatmap(pvt,xticklabels=False, yticklabels=True,cmap="YlGnBu")
fig = px.treemap(df, path=['State/UnionTerritory'], values='Confirmed', height=600, width=1000, title = 'State Wise Display Based on Total Number of Confirmed Cases')
#fig.update_layout(title_x = 0.5,geo=dict(showframe = True,showcoastlines = True))
fig.show()
fig = px.histogram(df, x="Confirmed", y="Cured", color="State/UnionTerritory", marginal="rug", hover_data=df.columns)
fig.show()
px.line(df,x='Date',y=['Confirmed','Deaths'], animation_frame = df['State/UnionTerritory'])
px.bar(df,x='State/UnionTerritory',y='Confirmed',color='Date',title='Covid - 19 - India',log_y=True)
px.bar(df,x='State/UnionTerritory',y='Deaths',color='Date',title='Covid - 19 - India',log_y=True)
cases = df[df['Date']==df['Date'].max()]['Confirmed']
name = df[df['Date']==df['Date'].max()]['State/UnionTerritory']
fig = px.pie(df, values=cases, names=name, title ="Confirmed COVID19 Cases in Percentage")
fig.show()
cases = df[df['Date']==df['Date'].max()]['Deaths']
name = df[df['Date']==df['Date'].max()]['State/UnionTerritory']
fig = px.pie(df, values=cases, names=name, title ="Deaths by COVID19 in Percentage")
fig.show()
cases = df[df['Date']==df['Date'].max()]['Confirmed']
name = df[df['Date']==df['Date'].max()]['State/UnionTerritory']
cured = df[df['Date']==df['Date'].max()]['Cured']
fig = px.scatter(df, x=cases, y=cured, size=cured, color=name, hover_name=name, log_x=True, size_max=60, title ="States Based on Total Number of Positive Cases Recorded against Non-Active Cases")
fig.show()
cases = df[df['Date']==df['Date'].max()]['Confirmed']
name = df[df['Date']==df['Date'].max()]['State/UnionTerritory']
deaths = df[df['Date']==df['Date'].max()]['Deaths']
fig = px.scatter(df, x=cases, y=deaths, size=deaths, color=name, hover_name=name, log_x=True, size_max=60, title ="States Based on Total Number of Positive Cases Recorded against Deaths")
fig.show()
plot = px.choropleth(df,
geojson="https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson",
featureidkey='properties.ST_NM',
locations='State/UnionTerritory',
color='Confirmed',
color_continuous_scale='Reds',animation_frame=dt)
plot.update_geos(fitbounds="locations", visible=False)
plot.show()
plot = px.choropleth(df,
geojson="https://gist.githubusercontent.com/jbrobst/56c13bbbf9d97d187fea01ca62ea5112/raw/e388c4cae20aa53cb5090210a42ebb9b765c0a36/india_states.geojson",
featureidkey='properties.ST_NM',
locations='State/UnionTerritory',
color='Deaths',
color_continuous_scale='Reds',animation_frame=dt)
plot.update_geos(fitbounds="locations", visible=False)
plot.show()